﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HGZP.BLL;

namespace BZXT
{
    /// <summary>
    /// 根据不同的角色，显示不同的角色信息、菜单
    /// </summary>
    public partial class Main1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            if (IsPostBack == false)
            {
                welcome.InnerHtml = "欢迎您：" + Session["user"] + "!&nbsp;&nbsp;";
                div_product_1.InnerHtml = "<br /><br />&nbsp;&nbsp;版权所有 Powered by 潍坊北大青鸟华光照排有限公司 © 2011-2020<br /><br /><br />";
                ltlMenu.Text = GetMenu();
                BindContent();
            }
        }

        /// <summary>
        /// 获取热门菜单
        /// 根据不同的角色绑定不同的菜单
        /// </summary>
        private string GetMenu()
        {
            //默认返回参数
            string liststr = "";
            //根据UserID提取用户对应权限菜单
            BaseUserBLL baseuser = new BaseUserBLL();
            System.Data.DataTable dtMenu = baseuser.GetUserFunction(Session["UserId"].ToString());
            CInfoMenuBLL infoMenu = new CInfoMenuBLL();
            //提取在首页显示的菜单
            System.Data.DataRow[] drMenuList = dtMenu.Select(string.Format("{0}='{1}'", infoMenu.bMain, "true"));
            if (drMenuList != null && drMenuList.Length > 0)
            {
                foreach (System.Data.DataRow drMenu in drMenuList)
                {
                    liststr += "[" + checkPr("B001", drMenu[infoMenu.sGuid].ToString(), drMenu[infoMenu.sFeaturesURL].ToString(), drMenu[infoMenu.sCaption].ToString().Trim())
                        + "]&nbsp;&nbsp;";
                }
            }
            //返回默认参数
            return liststr;
        }

        /// <summary>
        /// 组织成连接
        /// </summary>
        /// <param name="code">权限代码</param>
        /// <returns></returns>
        public string checkPr(string code, string ID, string href, string Name)
        {
            string str = string.Empty;
            if (code == "B001")
            {
                str += "<a class=\"menulist\" href=\"" + href + "\" target=\"sys_main\"  >" + Name + "</a>";
            }
            return str;
        }

        /// <summary>
        /// 绑定内容信息
        /// 根据不同的角色绑定不同的内容
        /// </summary>
        private void BindContent()
        {
            //根据UserId提取角色ＩＤ
            td_info.Visible = false;
            td_server.Visible = false;
            td_stat.Visible = false;
            td_upload.Visible = false;
            string _strScript =
                @"<script type=""text/javascript"" language=""javascript"">
                 function ChangeDiv(ID) {
        document.getElementById('td_product').className = 'm_up_bg';
        document.getElementById('div_product').style.display = 'none';
        ";
            CBaseUserRoleBLL userRoleBll = new CBaseUserRoleBLL();
            System.Data.DataTable dtRole = userRoleBll.F02_SelectHaveWhere(userRoleBll.sGuidBaseUser + "='" + Session["UserId"] + "'");
            //判断角色ID
            if (dtRole != null && dtRole.Rows.Count > 0)
            {
                foreach (DataRow row in dtRole.Rows)
                {
                    switch (row[userRoleBll.sGuidBaseRole].ToString())
                    {
                        case "4":
                            // 1.编审角色 显示编审信息
                            td_info.Visible = true;
                            _strScript +=
                                @"document.getElementById('td_info').className = 'm_up_bg';
                                document.getElementById('div_info').style.display = 'none';";
                            unlockList.InnerHtml = getNoReviewedInfo();
                            myList.InnerHtml = getReviewedInfo();
                            break;
                        case "1":
                            // 2.管理员   显示统计信息、服务器统计
                            td_server.Visible = true;
                            td_stat.Visible = true;
                            _strScript += @"document.getElementById('td_server').className = 'm_up_bg';
                                        document.getElementById('td_stat').className = 'm_up_bg';                   
                                        document.getElementById('div_server').style.display = 'none';
                                        document.getElementById('div_stat').style.display = 'none';";
                            break;
                        case "3":
                            // 3.资料上传 显示上传信息
                            td_upload.Visible = true;
                            _strScript +=
                                @" document.getElementById('td_upload').className = 'm_up_bg';
                            document.getElementById('div_upload').style.display = 'none';";
                            break;
                    }
                }
            }
            _strScript += @" document.getElementById(""div_"" + ID).style.display = '';
                    document.getElementById(""td_"" + ID).className = 'm_down_bg'
                     }</script>";
            ltlScript.Text = _strScript;
            _strScript = "";
        }

        /// <summary>
        /// 获取五条未审核的记录
        /// </summary>
        /// <returns></returns>
        private string getNoReviewedInfo()
        {
      /*      string _strContent = "<ul>";
            //提取5条未审核的信息
            BaseLoanBLL loanBll = new BaseLoanBLL();
            System.Data.DataTable dtNoReInfo = loanBll.GetHandleLoan(Session["UserId"].ToString(), 1, 4);
            if (dtNoReInfo != null && dtNoReInfo.Rows.Count > 0)
            {
                foreach (DataRow row in dtNoReInfo.Rows)
                {
                    _strContent += "<li>" +
                                   checkPr("B001", row["sGuid"].ToString(), "Workflow/handle.aspx?guid=" + row["sGuid"].ToString(),
                                           row["LoaName"].ToString() + "&nbsp;&nbsp;" + row["Edition"].ToString()) +
                                   "</li>";
                }
            }
            //转换成连接
            _strContent += "</ul>";
            return _strContent;*/
            return "";
        }

        /// <summary>
        /// 获取五条审核的记录
        /// </summary>
        /// <returns></returns>
        private string getReviewedInfo()
        {
            /*string _strContent = "<ul>";
            //提取5条审核的信息
            BaseLoanBLL loanBll = new BaseLoanBLL();
            System.Data.DataTable dtNoReInfo = loanBll.GetProcessedLoan(Session["UserId"].ToString(), 1, 4, "");
            if (dtNoReInfo != null && dtNoReInfo.Rows.Count > 0)
            {
                foreach (DataRow row in dtNoReInfo.Rows)
                {
                    _strContent += "<li>" +
                                   checkPr("B001", row["sGuid"].ToString(), "Workflow/Processed.aspx?guid=" + row["sGuid"].ToString(),
                                           row["LoaName"].ToString() + "&nbsp;&nbsp;" + row["Edition"].ToString()) +
                                   "</li>";
                }
            }
            //转换成连接
            _strContent += "</ul>";
            return _strContent;*/
            return "";
        }

        /// <summary>
        /// 退出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void linkbutton_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            Session.Abandon();
            this.ClientScript.RegisterStartupScript(GetType(), "", "<script>top.location.href='login.aspx';</script>");
        }
    }
}
